package com.fpx.metadata.controller;

import com.fpx.metadata.bean.po.DbInfo;
import com.fpx.metadata.bean.po.Tables;
import com.fpx.metadata.service.DbInfoService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author caowei
 */
@Api(value="/dbInfo", tags="需要爬取的数据库信息")
@RequestMapping("dbInfo")
@RestController
public class DbInfoController {

    @Autowired
    private DbInfoService dbInfoService;

    @ApiOperation(value="分页查询", notes = "分页查询")
    @GetMapping("queryListByPage/v1/{page}/{rows}")
    public PageInfo<DbInfo> queryListByPage(@PathVariable Integer page, @PathVariable Integer rows) {
        return dbInfoService.queryPageListByWhere(null, page, rows);
    }

    @ApiOperation(value="根据ID查询", notes = "根据ID查询")
    @GetMapping("queryById/{id}")
    public DbInfo queryById(@PathVariable Long id) {
        return dbInfoService.queryById(id);
    }


    @ApiOperation(value="保存", notes = "保存")
    @PostMapping("save")
    public String save(DbInfo dbInfo) {
        return dbInfoService.saveSelect(dbInfo) > 0 ? "succese" : "error";
    }

    @ApiOperation(value="更新", notes = "更新")
    @PutMapping("udpate")
    public String update(DbInfo dbInfo) {
        return dbInfoService.updateSelective(dbInfo) > 0 ? "succese" : "error";
    }

}
